//线图
var dataxAxis = new Array();
var predicationValue = new Array();
var realValue = new Array();
$.ajax({
    type: "POST",
    dataType: "json",
    url: "/getResultofMilk.do",
    data: {},
    async:false,
    success: function (response) {
       // console.log(response.map(Number));
        console.log(response.length);
        for(i=0; i < response.length; i++){
            dataxAxis[i] = i;
            predicationValue[i]=Number(response[i].split(" ")[10]);
            realValue[i]=Number(response[i].split(" ")[9]);
        }

    },
    error : function() {
        layer.alert("提交失败");
    }
});
var dataWeigth=[];
var dataName = new Array();
$.ajax({
    type: "POST",
    dataType: "json",
    url: "/getResultofweight.do",
    data: {},
    async:false,
    success: function (response) {
        data=JSON.parse(response);
        console.log(data.length);
        var i=0;
        for (var key in data) {
            dataName[i++]=key;     //获取key值
            dataWeigth.push({value:Number(data[key]),name:key});
        }

        console.log(data);
    },
    error : function() {
        layer.alert("提交失败");
    }
});
var myChart1 = echarts.init(document.getElementById('demo-1'));
var option = {
    title : {
        text: '',
        subtext: ''
    },
    tooltip : {
        trigger: 'axis'
    },
    legend: {
        data:['预测值','真实值']
    },
    toolbox: {
        show : true,
        feature : {
            mark : {show: true},
            dataView : {show: true, readOnly: false},
            magicType : {show: true, type: ['line', 'bar', 'stack', 'tiled']},
            restore : {show: true},
            saveAsImage : {show: true}
        }
    },
    calculable : true,
    dataZoom: [
        {
            show: true,
            realtime: true,
            start: 65,
            end: 85
        }
    ],
    xAxis : [
        {
            type : 'category',
            boundaryGap : false,
            data : dataxAxis,
        }
    ],
    yAxis : [
        {
            type : 'value'
        }
    ],
    series : [
        {
            name: '预测值',
            type: 'line',
            smooth: true,
            itemStyle: {normal: {}},
            data:predicationValue,
        },
        {
            name: '真实值',
            type: 'line',
            smooth: true,
            itemStyle: {normal: {}},
            data:realValue,
        }
    ]
};
myChart1.setOption(option);
//饼图
var myChart2 = echarts.init(document.getElementById('demo-2'));
var option = {
    title : {
        text: '',
        subtext: '',
        x:'center'
    },
    tooltip : {
        trigger: 'item',
        formatter: "{a} <br/>{b} : {c} ({d}%)"
    },
    legend: {
        orient: 'vertical',
        left: 'left',
        data: dataName
    },
    toolbox: {
        show : true,
        feature : {
            mark : {show: true},
            dataView : {show: true, readOnly: false},
            restore : {show: true},
            saveAsImage : {show: true}
        }
    },
    series : [
        {
            name: '',
            type: 'pie',
            radius : '55%',
            center: ['50%', '60%'],
            data:dataWeigth,
            itemStyle: {
                emphasis: {
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
            }
        }
    ]
};
myChart2.setOption(option);

var data3 = new Array();
for(i=0;i<56;i++){
    data3[i]=i;
};
var myChart3 = echarts.init(document.getElementById('demo-3'));
var option = {
    title : {
        text: '',
        subtext: ''
    },
    tooltip : {
        trigger: 'axis'
    },
    legend: {
        data:['权重']
    },
    toolbox: {
        show : true,
        feature : {
            mark : {show: true},
            dataView : {show: true, readOnly: false},
            magicType : {show: true, type: ['line', 'bar', 'stack', 'tiled']},
            restore : {show: true},
            saveAsImage : {show: true}
        }
    },
    calculable : true,
    xAxis : [
        {
            type : 'category',
            boundaryGap : false,
            data : data3,
        }
    ],
    yAxis : [
        {
            type : 'value'
        }
    ],
    series : [
        {
            name: '权重',
            type: 'bar',
            smooth: true,
            itemStyle: {normal: {}},
            data:data3,
        }
    ]
};
myChart3.setOption(option);